<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>

        //倒序
        /* var arr = [12,1,10,11,64,21,78,9];  // 数组存储的数据
        for (var i = 0; i < arr.length - 1; i++) {  // 比较的次数
        	for (var j = 0; j < arr.length - 1 - i; j++) { // 前后交换的次数
        		if (arr[j] < arr[j + 1]) {  // 判断大小
        			var temp = arr[j];  // 若判断的结果为真，则交换两个变量，若为假，直接进行下次比较
        			arr[j] = arr[j + 1];
        			arr[j + 1] = temp;
        		}
        	}
        }
        console.log(arr); */


        //正序
        /* var arr = [12,1,10,11,64,21,78,9];  
        for (var i = 0; i < arr.length; i++) {  
        	for (var j = i+1; j < arr.length; j++) { 
        		if (arr[i] > arr[j ]) {  
        			var temp;  
                    temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] =temp;
        		}
        	}
        }
        console.log(arr); */


        //使用sort原生js方法排序
        /* var arr = [12,1,10,11,64,21,78,9]; 
        arr.sort(function(i,j){
            return i-j;
        })
        console.log(arr); */


        //取偶数
        /* var arr = [12,1,10,11,64,21,78,9]; 
        var temp = [];
        for(var i = 0; i <arr.length;i++){
            if(arr[i]%2==0){
                temp.push(arr[i]);
            }
        }
        console.log(temp); */


        //使用filter筛选偶数
        /* var arr = [12,1,10,11,64,21,78,9];
        var b=arr.filter(x=>(x%2==0));
        console.log(b); */

        //不用箭头函数的时候
        /* var arr = [1, 2, 4, 5, 6, 9, 10, 15];
        var r = arr.filter(function (x) {
            return x % 2 !== 0;

        });
        console.log(r); */


        // 数组取反
        /* var arr = [12,1,10,11,64,21,78,9];
        for(var i=0;i<arr.length/2;i++){
            var temp = arr[i];
            arr[i] = arr[arr.length-i-1];
            arr[arr.length-i-1] = temp;
        }
        console.log(arr);  */
        //[9, 78, 21, 64, 11, 10, 1, 12]

        var arr = [12,1,10,11,64,21,78,9];
        arr.reverse();
        console.log(arr)     //本身数组的排序方法，reverse
    </script>
</body>

</html>